<template>
	<view class="content page">
		<status-bar title='修改密码'></status-bar>
		<view class="kite-bind-case">
			<view class="kite-phone-case">
				<view class="kite-phone-case flex-box align-center">
					<text class="iconfont icon-iconzhengli_shouji"></text>
					<view class="kite-bind-input flex">
						<input type="number" class="inputPhone" v-model="phoneNumber" maxlength="11" placeholder="请输入手机号码" />
					</view>
				</view>
			</view>
		</view>
		<view class="kite-bind-case">
			<view class="kite-email-case flex-box align-center">
				<text class="iconfont icon-mima1"></text>
				<view class="kite-bind-input flex">
					<input type="password" class="inputPhone" v-model="password" placeholder="请输入密码" />
				</view>
			</view>
		</view>
		<view class="kite-bind-case">
			<view class="kite-email-case flex-box align-center">
				<text class="iconfont icon-mima1"></text>
				<view class="kite-bind-input flex">
					<input type="password" class="inputPhone" v-model="cfmPassword" placeholder="请确认密码" />
				</view>
			</view>
		</view>
		<view class="kite-bind-case">
			<view class="kite-email-case flex-box align-center">
				<text class="iconfont icon-xinfeng"></text>
				<view class="kite-bind-input flex">
					<input type="number" class="inputPhone" v-model="phoneCode" placeholder="请输入验证码" />
					<view class="kite-codeBtn" @click="getCode">{{codeTxt}}</view>
				</view>
			</view>	
		</view>
		<view class="kite-bind-case">
			<view class="submitBtn btn3 thmeBg" :style="{'--color': color}" @click="unMpBindPhone">确 定</view>
			<!-- <view style="text-align: center;margin-top: 30upx;margin-bottom: 40upx;">
				<text class="thmeColor" style="text-decoration: underline;" :style="{'--color': color}">还没有账号，去注册</text>
			</view> -->
		</view>
		<showModel @cancelFunc='showModal = false' v-if='showModal' type='1'></showModel>
	</view>
</template>
<script>
	var timer,that;
	export default {
		data() {
			return {
				
				color: getApp().globalData.color,
				phoneNumber: '',
				phoneCode: '',
				codeTxt: '获取验证码',
				showModal: false, // 是否显示模态框
				bid: uni.getStorageSync('bid'),
				openid: uni.getStorageSync('openid'), 
				password: "",
				cfmPassword: "",
				vid: uni.getStorageSync('vid'),
				disabled: true
			}
		},
		onShareAppMessage(option) {
			let shareData = uni.getStorageSync('shareData');
			let vid = uni.getStorageSync('vid');
			return {
				title: shareData.title,
				desc: shareData.desc,
				path: '/pages/index/index?share_v_id=' + vid+'&pageType=99',
				imageUrl: shareData.imageUrl
			}
		},
		onLoad(e) {
			that = this
			
		},
		methods: {
			getCode: function() {
				if (that.phoneNumber == '') {
					uni.showToast({
						title: '手机号码不能为空!',
						icon: "none",
						duration: 2000
					})
					return
				}
				if (!that.$reg.phone.test(that.phoneNumber) && that.phoneNumber != '') {
					uni.showToast({
						title: '手机号码格式不正确!',
						icon: 'none',
						duration: 2000
					})
					return
				}
				let count = 60;
				if (that.disabled) {
					that.$http.post({
						url: '/zzj_singleSaleApi/reverCode',
						data: {
							phone: that.phoneNumber,
							bid: that.bid,
						}
					}).then(res => {
						if (res.status) {
							that.codeTxt = '获取验证码';
							that.disabled = false;
							timer = setInterval(() => {
								if (count > 0) {
									count -= 1;
									that.codeTxt = '重新发送(' + count + 's)'
								} else {
									that.codeTxt = '获取验证码';
									clearInterval(timer);
									that.disabled = true;
								}
							}, 1000)
						}
						uni.showToast({
							icon: "none",
							title: res.msg,
							duration: 2000
						})
					})
				}
			},
			unMpBindPhone: function() {
				if(!that.phoneNumber || that.phoneNumber == ' '){
					uni.showToast({
						title: '请输入手机号',
						icon: "none"
					});
					return
				}
				if (!that.$reg.phone.test(that.phoneNumber) && that.phoneNumber != '') {
					uni.showToast({
						title: '手机号码格式有误 ~',
						icon: "none"
					});
				    return
				}
				if (!that.password || that.password.trim() == '') {
					uni.showToast({
						title: "请输入密码",
						icon: "none"
					});
					return
				}
				if (!that.cfmPassword || that.cfmPassword.trim() == '') {
					uni.showToast({
						title: "请确认密码",
						icon: "none"
					});
					return
				}
				if (that.password != that.cfmPassword) {
					uni.showToast({
						title: "密码输入不一致~",
						icon: "none"
					});
					return
				}
				if(!that.phoneCode || that.phoneCode == ' '){
					uni.showToast({
						title: '验证码不能为空',
						icon: "none"
					});
					return
				}
				that.$http.post({
					url: '/zzj_singleSaleApi/changePasswd',
					data: {
						bid: that.bid,
						openid: uni.getStorageSync('clientid'),
						phone: that.phoneNumber,
						password: that.password,
						verCode: that.phoneCode
					}
				}).then(res => {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
					if (res.errcode == '00000') {
						setTimeout(function() {
							that.backHome()
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style scoped>
	.kite-bind-case {
		width: 100%;
		height: auto;
		overflow: hidden;
	}

	.btn3 {
		width: 650upx;
		height: 88upx;
		line-height: 88upx;
	}

	.submitBtn.btn3 {
		margin-top: 40upx;
	}

	.kite-bind-tips {
		width: 100%;
		height: 50upx;
		font-size: 24upx;
		font-weight: 400;
		color: #ff4b4e;
		letter-spacing: 2upx;
		margin-top: 40upx;
		margin-left: 60upx;
	}

	.kite-onekey-btn {
		background: #FFFFFF;
		font-size: 28upx;
		font-weight: 400;
		color: #333333;
		text-align: center;
	}

	.kite-codeBtn {
		position: absolute;
		right: 0;
		line-height: 70upx;
		width: 160upx;
		text-align: center;
		color: #999;
		border-radius: 16upx;
		height: 70upx;
		float: right;
		border: 2upx solid #DDDDDD;
		font-size: 22upx;
		z-index: 8;
		bottom: 20upx;
	}

	.kite-bind-input {
		position: relative;
		height: 120upx;
		margin-left: 30upx;
		padding: 20upx 0;
		border: none;
	}

	.kite-bind-input:before {
		position: absolute;
		content: '';
		bottom: 0;
		background: #999999;
		width: 100%;
		height: 2upx;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
	}

	.kite-phone-case,
	.kite-email-case {
		position: relative;
		width: 100%;
		height: 140upx;
		padding: 10upx 0;
	}
	.kite-phone {
		position: absolute;
		left: 0;
		width: 15%;
		height: 100upx;
		text-align: center;
	}

	.kite-phone image {
		width: 40upx;
		height: 40upx;
		margin: 30upx 0;
	}
	.kite-bind-case {
		padding: 0 50upx;
	}

	.kite-bind-title {
		width: 100%;
		height: 82upx;
		font-size: 36upx;
		line-height: 82upx;
		color: #666666;
		text-align: center;
		letter-spacing: 4upx;
		font-weight: bold;
	}

	.kite-bind-title text {
		color: #666666;
		font-size: 36upx;
	}

	.kite-case {
		margin-top: 60upx;
		width: 100%;
		height: 80upx;
	}

	.kite-one-button {
		width: 690upx;
		height: 80upx;
		line-height: 80upx;
		text-align: center;
		background: #FF4400;
		border-radius: 200upx;
		margin: 0 auto;
		font-size: 24upx;
		font-weight: 400;
		color: #FFFFFF;
	}

	.content {
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
		padding-top: 90rpx;
	}

	.inputText {
		width: 100%;
		padding: 0 30upx;
	}

	.inputBox,
	.inputNumber {
		width: 100%;
		height: 80upx;
	}

	.inputBox,
	.submitBtn {
		margin-top: 60upx;
	}

	.inputNumber {
		position: relative;
		border: none;
		/* border: 1upx solid #999999; */
		border-radius: 64upx;
		line-height: 80upx;
		padding: 0 30upx;
		margin-bottom: 40upx;
	}

	.inputNumber:before {
		content: '';
		position: absolute;
		top: 0;
		left: 0;
		border: 1px solid #000;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		width: 200%;
		height: 200%;
		-webkit-transform: scale(0.5);
		transform: scale(0.5);
		-webkit-transform-origin: left top;
		transform-origin: left top;
	}

	.inputPhone {
		width: 100%;
		float: left;
		height: 48upx;
		margin-top: 16upx;
		margin-left: 20upx;
	}

	.inputCode .inputPhone {
		width: calc(50% - 30upx);
	}

	.inputCode {
		padding-right: 0;
	}

	.codeBtn {
		width: calc(50% - 30upx);
		text-align: center;
		color: #FFFFFF;
		border-radius: 0 64upx 64upx 0;
		background: #FF4400;
		height: calc(100% + 2upx);
		float: right;
		border: 2upx solid #ff4b4e;
	}
	.iconfont{
		font-size: 46rpx;
		color: #666;
		width: 46rpx;
		text-align: center;
	}
</style>
